package comando;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import modelo.Usuario;
import servico.UsuarioAppService;

public class ComandoEfetuaLogin {

    private String proxima;

    public ComandoEfetuaLogin() {
        proxima = "/jsp/exibeLogin.jsp";
    }

    public String executar(HttpServletRequest request) {
        String login = request.getParameter("login");
        String senha = request.getParameter("senha");

        UsuarioAppService umUsuarioAppService = new UsuarioAppService();
        Usuario umUsuario = umUsuarioAppService.valida(login, senha);

        HttpSession sessao = request.getSession();
        if (umUsuario != null) {
            sessao.setAttribute("login", umUsuario);
            String cmd = (String) sessao.getAttribute("cmd");
            proxima = "/arearestrita/ServletRevista?cmd=" + cmd;
        } else {
            boolean erro = true;
            request.setAttribute("erro", erro);
        }
        return proxima;
    }
}
